/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GeraRecomendacao.java
 *
 * Created on 29/05/2011, 00:41:29
 */
package MenuPrincipal;

import Classes.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author JAVA-LI
 * 
 */
public class GeraRecomendacaoEspanhol extends javax.swing.JFrame {
    private ArrayList<String> list1;
    private ArrayList<Estabelecimento> estabelecimentos;
    private ArrayList<Estabelecimento> recomendacoes;
    private RepositorioDeUsuarios repositorio;
    private Usuario usuarioNaoCadastrado;
    private ArrayList<Opniao> opNaoCadastradas;
    private String[] conceito = {"Incrível. sensacional. impressionante","Muito bom","Bastante bom","É bonzinho","Não é ruim","Não conheço","Acho um pouco ruim","Acho ruim","Acho bastante ruim","Acho muito ruim","Detesto"};
    private String caminhoEstabelecimentos = "lista_estabelecimentos_projeto_lp2-v2.data";
    private String caminhoOpnioes = "opinioes-dos-usuarios-v2.data";
    
    /** Creates new form GeraRecomendacao */
    public GeraRecomendacaoEspanhol() {
        
        opNaoCadastradas = new ArrayList<Opniao>();
        usuarioNaoCadastrado = new Usuario("", "", opNaoCadastradas);
        repositorio = new RepositorioDeUsuarios();
        estabelecimentos = new ArrayList<Estabelecimento>();
        CarregaEstabelecimentos cargarEstab = new CarregaEstabelecimentos(caminhoEstabelecimentos);
        
        try {
            estabelecimentos = cargarEstab.getEstabelecimentos();
        } catch (Exception ex) {
            Logger.getLogger(GeraRecomendacaoEspanhol.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        CarregaUsuarios cargarUser = new CarregaUsuarios(caminhoOpnioes, estabelecimentos);
        repositorio = cargarUser.getUser();
        
        list1 = new ArrayList<String>();
        for(Usuario usuario : repositorio.getUsuarios()){
            list1.add(usuario.toString());
        }
        initComponents();
        comboxPerfilUser.setEnabled(false);
        try{
            javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            javax.swing.SwingUtilities.updateComponentTreeUI(this);
        }catch(Exception e){
            System.out.println(e);
        }
        for(Estabelecimento es :estabelecimentos){
                try {
                    usuarioNaoCadastrado.adicionaPreferencia(new Opniao(es,0,conceito[5]));
                } catch (Exception ex) {
                    Logger.getLogger(GeraRecomendacaoEspanhol.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
    }
    
    private String[] preencheLista(List<Estabelecimento> estabelecimentos){
        
        String[] s = new String[estabelecimentos.size()];
        int i=0;
        for(Estabelecimento e : estabelecimentos){
            s[i++] = e.toString();
        }
        
        return s;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelGeraRecomendacoes = new javax.swing.JPanel();
        painelTipoUser = new javax.swing.JPanel();
        comboBoxUsuarios = new javax.swing.JComboBox();
        painelPerfilUser = new javax.swing.JPanel();
        comboxPerfilUser = new javax.swing.JComboBox();
        painelBarraEstab = new javax.swing.JPanel();
        comboxRestaurates = new javax.swing.JComboBox();
        painelConceito = new javax.swing.JPanel();
        comboxConceito = new javax.swing.JComboBox();
        botaoGeraRecomendacao = new javax.swing.JButton();
        botaoVotar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        comboboxNumero = new javax.swing.JComboBox();
        labelNomeDoUsuario = new javax.swing.JLabel();
        textUsuario = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        comboboxRecomenda = new javax.swing.JComboBox();
        botaoSalvarPerfil = new javax.swing.JButton();
        painelRecomendacoesGeradas = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jMenuBar1 = new javax.swing.JMenuBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        painelGeraRecomendacoes.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Genera recomendacion", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        painelGeraRecomendacoes.setPreferredSize(new java.awt.Dimension(650, 300));

        painelTipoUser.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo do usuario"));

        comboBoxUsuarios.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Usuario no registrado", "Usuario registrado" }));
        comboBoxUsuarios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                comboBoxUsuariosMouseClicked(evt);
            }
        });
        comboBoxUsuarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBoxUsuariosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout painelTipoUserLayout = new javax.swing.GroupLayout(painelTipoUser);
        painelTipoUser.setLayout(painelTipoUserLayout);
        painelTipoUserLayout.setHorizontalGroup(
            painelTipoUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboBoxUsuarios, javax.swing.GroupLayout.Alignment.TRAILING, 0, 188, Short.MAX_VALUE)
        );
        painelTipoUserLayout.setVerticalGroup(
            painelTipoUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelTipoUserLayout.createSequentialGroup()
                .addComponent(comboBoxUsuarios, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
                .addContainerGap())
        );

        painelPerfilUser.setBorder(javax.swing.BorderFactory.createTitledBorder("Perfiles de los usuarios"));

        comboxPerfilUser.setModel(new javax.swing.DefaultComboBoxModel(list1.toArray()));
        comboxPerfilUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboxPerfilUserActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout painelPerfilUserLayout = new javax.swing.GroupLayout(painelPerfilUser);
        painelPerfilUser.setLayout(painelPerfilUserLayout);
        painelPerfilUserLayout.setHorizontalGroup(
            painelPerfilUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboxPerfilUser, 0, 259, Short.MAX_VALUE)
        );
        painelPerfilUserLayout.setVerticalGroup(
            painelPerfilUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboxPerfilUser, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
        );

        painelBarraEstab.setBorder(javax.swing.BorderFactory.createTitledBorder("Instalaciones"));

        comboxRestaurates.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Baixinho Bar e Restaurante", "Bar do Cuscuz e Restaurante", "Bar do George", "Bar do Santos", "Bodão Bar e Restaurante", "Bonaparte", "Bongustaio", "Cabana do Possidônio", "Cantina da Sayonara", "Cantina de Dona Inês", "Cantina de Olavo", "Cantina do Departamento de Meteorologia", "Cantina do Hall das Placas", "Cantinho Universitário", "Chinatown", "Divino Fogão", "Fazenda", "Giraffas", "Girassol", "Gulas", "Manoel da Carne de Sol", "Marmitaria ArtCulinária", "Marmitaria Bom Paladar", "Marmitaria da Mama", "Paladar", "Pedro da Picanha", "Qdoca Bar e Restaurante", "Restaurante Brasília", "Restaurante da Quadra", "Restaurante do Alexandre", "Restaurante do Paraná", "Restaurante Golden In China", "Restaurante Lay China", "Riso", "Spolleto", "Super China Restaurante", "Trailer do Marcus", "Tuxá", "Varandas bar e restaurante" }));

        javax.swing.GroupLayout painelBarraEstabLayout = new javax.swing.GroupLayout(painelBarraEstab);
        painelBarraEstab.setLayout(painelBarraEstabLayout);
        painelBarraEstabLayout.setHorizontalGroup(
            painelBarraEstabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboxRestaurates, 0, 263, Short.MAX_VALUE)
        );
        painelBarraEstabLayout.setVerticalGroup(
            painelBarraEstabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboxRestaurates, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        painelConceito.setBorder(javax.swing.BorderFactory.createTitledBorder("Concepto"));

        comboxConceito.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Increíble, asombroso, impresionante", "Muy bueno", "Bastante bien", "Agradable", "No es malo", "No lo sé", "Un poco mal", "Mal", "Bastante ma", "Muy mal", "Odio" }));

        javax.swing.GroupLayout painelConceitoLayout = new javax.swing.GroupLayout(painelConceito);
        painelConceito.setLayout(painelConceitoLayout);
        painelConceitoLayout.setHorizontalGroup(
            painelConceitoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboxConceito, 0, 238, Short.MAX_VALUE)
        );
        painelConceitoLayout.setVerticalGroup(
            painelConceitoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboxConceito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        botaoGeraRecomendacao.setText("Generar recomendacion");
        botaoGeraRecomendacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoGeraRecomendacaoActionPerformed(evt);
            }
        });

        botaoVotar.setText("Votar");
        botaoVotar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoVotarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Número", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        comboboxNumero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboboxNumero, 0, 56, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboboxNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        labelNomeDoUsuario.setText("Nombre de usuario: ");

        textUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textUsuarioActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo de recomendaciones"));

        comboboxRecomenda.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Por popularidad", "Semejanza" }));
        comboboxRecomenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboboxRecomendaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboboxRecomenda, 0, 137, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(comboboxRecomenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        botaoSalvarPerfil.setText("Guardar perfil");
        botaoSalvarPerfil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSalvarPerfilActionPerformed(evt);
            }
        });

        painelRecomendacoesGeradas.setBorder(javax.swing.BorderFactory.createTitledBorder("Recomendaciones generadas"));

        jList1.setModel(new javax.swing.AbstractListModel() {
            String strings[] = {};
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        javax.swing.GroupLayout painelRecomendacoesGeradasLayout = new javax.swing.GroupLayout(painelRecomendacoesGeradas);
        painelRecomendacoesGeradas.setLayout(painelRecomendacoesGeradasLayout);
        painelRecomendacoesGeradasLayout.setHorizontalGroup(
            painelRecomendacoesGeradasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 584, Short.MAX_VALUE)
        );
        painelRecomendacoesGeradasLayout.setVerticalGroup(
            painelRecomendacoesGeradasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelRecomendacoesGeradasLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout painelGeraRecomendacoesLayout = new javax.swing.GroupLayout(painelGeraRecomendacoes);
        painelGeraRecomendacoes.setLayout(painelGeraRecomendacoesLayout);
        painelGeraRecomendacoesLayout.setHorizontalGroup(
            painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelGeraRecomendacoesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(painelRecomendacoesGeradas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(painelGeraRecomendacoesLayout.createSequentialGroup()
                        .addGroup(painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(painelGeraRecomendacoesLayout.createSequentialGroup()
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelGeraRecomendacoesLayout.createSequentialGroup()
                                .addGroup(painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(painelBarraEstab, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(painelTipoUser, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(15, 15, 15))
                            .addComponent(painelPerfilUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(painelGeraRecomendacoesLayout.createSequentialGroup()
                                .addComponent(labelNomeDoUsuario)
                                .addGap(18, 18, 18)
                                .addComponent(textUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(botaoGeraRecomendacao, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(botaoSalvarPerfil)
                            .addComponent(botaoVotar, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(painelConceito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        painelGeraRecomendacoesLayout.setVerticalGroup(
            painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelGeraRecomendacoesLayout.createSequentialGroup()
                .addGroup(painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(painelTipoUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(painelGeraRecomendacoesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelNomeDoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botaoSalvarPerfil)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addComponent(painelPerfilUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelGeraRecomendacoesLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(painelConceito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(botaoVotar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botaoGeraRecomendacao))
                    .addGroup(painelGeraRecomendacoesLayout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(painelBarraEstab, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(painelGeraRecomendacoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(11, 11, 11)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(painelRecomendacoesGeradas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64))
        );

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(painelGeraRecomendacoes, javax.swing.GroupLayout.DEFAULT_SIZE, 628, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(painelGeraRecomendacoes, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE)
                .addGap(48, 48, 48))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

   
    private void botaoGeraRecomendacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoGeraRecomendacaoActionPerformed
        // TODO add your handling code here:
        if(comboBoxUsuarios.getSelectedIndex()==0){
            if(comboboxRecomenda.getSelectedIndex()==0){
                RecomendacaoGlobal rG = new RecomendacaoGlobal();
                try {
                    recomendacoes = rG.Sugeri(repositorio, comboboxNumero.getSelectedIndex()+1);
                } catch (Exception ex) {
                    Logger.getLogger(GeraRecomendacaoEspanhol.class.getName()).log(Level.SEVERE, null, ex);
                }
            }else{
                RecomendacaoPersonalizada rP = new RecomendacaoPersonalizada();
            
                try {
                    
                recomendacoes = rP.sugeriPersonalizado(repositorio,usuarioNaoCadastrado, comboboxNumero.getSelectedIndex()+1);
       
                } catch (Exception ex) {
                Logger.getLogger(GeraRecomendacaoEspanhol.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }else{
            if(comboboxRecomenda.getSelectedIndex()==1){
                RecomendacaoPersonalizada rP = new RecomendacaoPersonalizada();
            
                try {
                    recomendacoes = rP.sugeriPersonalizado(repositorio,repositorio.getUsuarioPorIndice(comboxPerfilUser.getSelectedIndex()),comboboxNumero.getSelectedIndex()+1);
       
                } catch (Exception ex) {
                    Logger.getLogger(GeraRecomendacaoEspanhol.class.getName()).log(Level.SEVERE, null, ex);
                }
            }else{
                RecomendacaoGlobal rG = new RecomendacaoGlobal();
                try {
                    recomendacoes = rG.Sugeri(repositorio, comboboxNumero.getSelectedIndex()+1);
                } catch (Exception ex) {
                    Logger.getLogger(GeraRecomendacaoEspanhol.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
        }
        jList1.setModel(new javax.swing.AbstractListModel() {
            String strings[] = preencheLista(recomendacoes);
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        
    }//GEN-LAST:event_botaoGeraRecomendacaoActionPerformed

    private void comboBoxUsuariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBoxUsuariosActionPerformed
        // TODO add your handling code here:
        
        if(comboBoxUsuarios.getSelectedIndex()==1){
            comboxRestaurates.setEnabled(false);
            painelBarraEstab.setEnabled(false);
            labelNomeDoUsuario.setEnabled(false);
            textUsuario.setEnabled(false);
            painelConceito.setEnabled(false);
            comboxConceito.setEnabled(false);
            botaoVotar.setEnabled(false);
            botaoSalvarPerfil.setEnabled(false);
            comboxPerfilUser.setEnabled(true);
            
            
            
            
        }else{
            comboxRestaurates.setEnabled(true);
            painelBarraEstab.setEnabled(true);
            labelNomeDoUsuario.setEnabled(true);
            textUsuario.setEnabled(true);
            painelConceito.setEnabled(true);
            comboxConceito.setEnabled(true);
            botaoVotar.setEnabled(true);
            botaoSalvarPerfil.setEnabled(true);
            comboxPerfilUser.setEnabled(false);
            
        }
    }//GEN-LAST:event_comboBoxUsuariosActionPerformed

    private void comboBoxUsuariosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_comboBoxUsuariosMouseClicked
        // TODO add your handling code here:
        if(comboBoxUsuarios.getSelectedIndex()==1){
            comboxRestaurates.setEnabled(false);
            painelBarraEstab.setEnabled(false);
            labelNomeDoUsuario.setEnabled(false);
            textUsuario.setEnabled(false);
            comboxConceito.setEnabled(false);
            painelConceito.setEnabled(false);
            
            
            
        }else{
            comboxRestaurates.setEnabled(true);
            painelBarraEstab.setEnabled(true);
            labelNomeDoUsuario.setEnabled(true);
            textUsuario.setEnabled(true);
            comboxConceito.setEnabled(true);
            painelConceito.setEnabled(true);
        }
    }//GEN-LAST:event_comboBoxUsuariosMouseClicked

    private void textUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textUsuarioActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_textUsuarioActionPerformed

    private void comboxPerfilUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboxPerfilUserActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_comboxPerfilUserActionPerformed
    private String getData(){
        DateFormat date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date dat = new Date();
        return date.format(dat);
        
    }
    private static void EscreveOpinioes(Usuario user,String caminho) throws IOException{
                String gravar = user.getDataDoCadastro()+";"+user.getNome();
                for(Opniao opi : user.getPreferencias()){
                    gravar +=";"+opi.toString();
                }
                
		String diretorioOpinioes = caminho;
		BufferedWriter out = null;
		String novaLinha = System.getProperty("line.separator"); 
		try {
			out = new BufferedWriter(new FileWriter(diretorioOpinioes, true));
			out.write(gravar+novaLinha);
		}catch(IOException erro){
			System.err.println(erro.getMessage());
		}
		finally{
			out.close();
		}
                
	}
    
    private void botaoVotarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoVotarActionPerformed
        try {
            Opniao opi = new Opniao(estabelecimentos.get(comboxRestaurates.getSelectedIndex()), 5-comboxConceito.getSelectedIndex(), conceito[comboxConceito.getSelectedIndex()]);
            usuarioNaoCadastrado.mudaPreferencia(opi);
        } catch (Exception ex) {
            Logger.getLogger(GeraRecomendacaoEspanhol.class.getName()).log(Level.SEVERE, null, ex);
        }
          
        
    }//GEN-LAST:event_botaoVotarActionPerformed

    private void botaoSalvarPerfilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSalvarPerfilActionPerformed
        // TODO add your handling code here:
        usuarioNaoCadastrado.setNome(textUsuario.getText());
        usuarioNaoCadastrado.setDataDoCadastro(getData());
        try {
            EscreveOpinioes(usuarioNaoCadastrado,caminhoOpnioes);
        } catch (IOException ex) {
            Logger.getLogger(GeraRecomendacaoEspanhol.class.getName()).log(Level.SEVERE, null, ex);
        }
        comboxPerfilUser.addItem(usuarioNaoCadastrado.toString());

    }//GEN-LAST:event_botaoSalvarPerfilActionPerformed

    private void comboboxRecomendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboboxRecomendaActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_comboboxRecomendaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GeraRecomendacaoEspanhol().setVisible(true);
            }
        });
    }
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoGeraRecomendacao;
    private javax.swing.JButton botaoSalvarPerfil;
    private javax.swing.JButton botaoVotar;
    private javax.swing.JComboBox comboBoxUsuarios;
    private javax.swing.JComboBox comboboxNumero;
    private javax.swing.JComboBox comboboxRecomenda;
    private javax.swing.JComboBox comboxConceito;
    private javax.swing.JComboBox comboxPerfilUser;
    private javax.swing.JComboBox comboxRestaurates;
    private javax.swing.JList jList1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelNomeDoUsuario;
    private javax.swing.JPanel painelBarraEstab;
    private javax.swing.JPanel painelConceito;
    private javax.swing.JPanel painelGeraRecomendacoes;
    private javax.swing.JPanel painelPerfilUser;
    private javax.swing.JPanel painelRecomendacoesGeradas;
    private javax.swing.JPanel painelTipoUser;
    private javax.swing.JTextField textUsuario;
    // End of variables declaration//GEN-END:variables
}
